def find(arr, target):
    # arr是二维数组
    n = len(arr)
    m = len(arr[0])

    # 尽可能排除行或列
    row_lo = 0
    col_high = m - 1

    while row_lo < n and col_high > -1:
        # 二分
        if target > arr[row_lo][col_high]:
            # 排除当前行
            row_lo += 1
        elif target < arr[row_lo][col_high]:
            # 排除当前列
            col_high -= 1
        else:
            return row_lo, col_high
    return -1, -1


if __name__ == "__main__":
    arr = [
        [1, 2, 8, 9],
        [2, 4, 9, 12],
        [4, 7, 10, 13],
        [6, 8, 11, 15]
    ]

    print(find(arr, 7))

